package gdconf

import (
	"server_cluster/common/logger"
)

// 场景npc配置表

const (
	AppearCondAcceptQuestAppear    = 1 // 接取子任务时出现 参数1:子任务id
	AppearCondFinishQuestAppear    = 2 // 完成子任务时出现 参数1:子任务id
	AppearCondFinishQuestDisappear = 3 // 完成子任务时消失 参数1:子任务id
)

type NpcConfig struct {
	NpcId          int32         `csv:"ID" gorm:"primary_key;autoIncrement:false"` // npcid
	SceneId        int32         `csv:"SceneId,omitempty"`                         // 所在场景
	AppearCondList IntArrayArray `csv:"AppearType,omitempty"`                      // 出现条件列表
}

func (n *NpcConfig) TableName() string {
	return "config_npc"
}

func (g *GameDataConfig) saveNpcConfig() {
	saveTableToDb[NpcConfig](g.Db, readTable[NpcConfig](g.CsvPathPrefix+"Actor_Npc.csv"))
}

func (g *GameDataConfig) loadNpcConfig() {
	g.GameDataMaps.NpcConfigMap = make(map[int32]*NpcConfig)
	for _, npcConfig := range loadTableFromDb[NpcConfig](g.Db) {
		g.GameDataMaps.NpcConfigMap[npcConfig.NpcId] = npcConfig
	}
	logger.Info("NpcConfig Count: %v", len(g.GameDataMaps.NpcConfigMap))
}

func GetNpcConfig(npcId int32) *NpcConfig {
	value, exist := CONF.GameDataMaps.NpcConfigMap[npcId]
	if !exist {
		logger.Error("[ConfigNotFound] NpcConfig, npcId: %v", npcId)
		return nil
	}
	return value
}

func GetNpcConfigMap() map[int32]*NpcConfig {
	return CONF.GameDataMaps.NpcConfigMap
}
